package com.burgeon.backend.EnterpriseWeChat.rest.VipInfo;
/**
 * 添加采购退货单的头和明细（上海）
 */

import com.burgeon.backend.EnterpriseWeChat.entity.VipFamily;
import com.burgeon.backend.EnterpriseWeChat.entity.VipSkinInfo;
import com.burgeon.backend.Rest.base.RESTBase;
import org.apache.http.util.TextUtils;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class processFamilyInfo extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public processFamilyInfo(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(VipFamily vipFamily) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(vipFamily), url);
//        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");

        if (!"0".equals(code)) {
            throw new Exception(message);
        }
        String objectid = new JSONArray(str).getJSONObject(0).getString("objectid");
        return objectid;

    }

    private MultiValueMap Data(VipFamily vipFamily) {
      //  System.err.println("'"+retail.getC_STORE_ID()+"'");

        HashMap params = new HashMap();
//        params.put("id" , "APP_FAMILY_INFORMATION");

        HashMap masterObjs = new HashMap(); //头表记录对象，采购退货单
        masterObjs.put("table", "APP_FAMILY_INFORMATION");
        masterObjs.put("ak", vipFamily.getId());

        masterObjs.put("NAME", vipFamily.getName());

        masterObjs.put("CALL_TYPE", vipFamily.getCallType());

        masterObjs.put("BIRTHDAY", vipFamily.getBirthday());

        if (!TextUtils.isEmpty(vipFamily.getDescription())) {
            masterObjs.put("DESCRIPTION", vipFamily.getDescription());
        }

        params.put("masterobj", masterObjs);
//        params.put("submit", "true");//是否提交
        System.err.println(params);
        return DATA("ProcessOrder", params, account, password);
    }

    public static void main(String[] args) {
        processFamilyInfo g = new processFamilyInfo("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            VipFamily vipFamily = new VipFamily();
            vipFamily.setId("45");
            vipFamily.setCallType("妻子");
            vipFamily.setName("测试");
            vipFamily.setBirthday("20201214");
            vipFamily.setDescription("测试");
            System.err.println(g.getData(vipFamily));
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e.getMessage());
        }
    }
}
